import React, { PureComponent } from 'react';
import { Card, Button, message, Form, InputNumber, Select } from 'antd';
import { PageContainer } from '@ant-design/pro-layout'
import { setting, settingShow } from '@/services/setting'
import { isDevelopment, isTzsbpx, isZhengda, hasSend,isHangda, isZhongZheng ,isLyxiehui,isXincheng} from '@/utils/utils'
import 'braft-editor/dist/index.css'
const layout = {
    labelCol: { span: 2 },
    wrapperCol: { span: 16 },
};
const tailLayout = {
    wrapperCol: { offset: 2, span: 16 },
};
class Index extends PureComponent<any, any> {
    constructor(props: any) {
        super(props)
        this.state = {
            exercise_num: 100,
            exercise_integral: 0,
            simulation_integral: 0,
            default_integral: 0,
            permissions_day: 0,
            exam_send: null,
            learn_alert: null
        }
    }
    componentDidMount() {
        settingShow().then(res => {
            if (!res) return;
            const { exercise_num, exercise_integral, simulation_integral, default_integral, permissions_day, exam_send, learn_alert } = res;

            this.setState({
                exercise_num, exercise_integral, simulation_integral, default_integral, permissions_day, exam_send, learn_alert
            })
        })
    }
    changeNumber = (e: any, name: any) => {
        this.setState({
            [name]: e
        })
    }
    submitHandle = () => {
        const { exercise_num, exercise_integral, simulation_integral, default_integral, permissions_day, exam_send, learn_alert } = this.state;
        setting({ exercise_num, exercise_integral, simulation_integral, default_integral, permissions_day, exam_send, learn_alert }).then(res => {
            if (res.status === 1) {
                message.success('已保存')
            } else {
                message.error('保存失败')
            }
        })
    }
    render() {
        const { exercise_num, exercise_integral, simulation_integral, default_integral, permissions_day, exam_send, learn_alert } = this.state;
        return (
            <PageContainer>
                <Card>
                    <Form >
                        <Form.Item {...layout} label="专项练习设置">
                            每次练习题数 <InputNumber min={0} disabled value={exercise_num} onChange={(e) => this.changeNumber(e, 'exercise_num')} /> 道，
                            扣除 <InputNumber min={0} value={exercise_integral} onChange={(e) => this.changeNumber(e, 'exercise_integral')} /> 积分
                        </Form.Item>
                        <Form.Item {...layout} label="模拟考试设置">
                            模拟每次扣除 <InputNumber min={0} value={simulation_integral} onChange={(e) => this.changeNumber(e, 'simulation_integral')} /> 积分
                            </Form.Item>
                        <Form.Item {...layout} label="积分设置">
                            新增学员默认积分 <InputNumber min={0} value={default_integral} onChange={(e) => this.changeNumber(e, 'default_integral')} /> 分
                            </Form.Item>
                        <Form.Item {...layout} label="权限设置">
                            新增学员开通权限 <Select style={{ width: 88 }} value={permissions_day} onChange={(e) => this.changeNumber(e, 'permissions_day')} >
                                <Select.Option key="1" value={15}>15</Select.Option>
                                <Select.Option key="2" value={30}>30</Select.Option>
                                <Select.Option key="3" value={45}>45</Select.Option>
                                <Select.Option key="4" value={60}>60</Select.Option>
                                {
                                    (isTzsbpx() || isZhengda()||isHangda()||isLyxiehui()) && <Select.Option key="5" value={90}>90</Select.Option>
                                }
                                {
                                    isXincheng()&&<Select.Option key="6" value={120}>120</Select.Option>
                                }
                                {
                                    (isTzsbpx()||isZhongZheng()) && <Select.Option key="7" value={180}>180</Select.Option>
                                }
  {
                                    isTzsbpx() && <Select.Option key="8" value={365}>365</Select.Option>
                                }
                            </Select> 天
                            </Form.Item>
                        {
                            (isDevelopment() || hasSend()) && <React.Fragment>
                                <Form.Item {...layout} label="考试推送设置">
                                    微信推送提醒从设置考试时间前  <Select onChange={(e) => this.changeNumber(e, 'exam_send')} value={exam_send} style={{ width: 120 }} placeholder="请选择天数">
                                    <Select.Option key="1" value={'0'}>请选择</Select.Option>
                                        <Select.Option key="5" value={5}>5</Select.Option>
                                        <Select.Option key="7" value={7}>7</Select.Option>
                                        <Select.Option key="14" value={14}>14</Select.Option>
                                        <Select.Option key="30" value={30}>30</Select.Option>
                                    </Select> 天开始进行考试通知推送
                        </Form.Item>
                                <Form.Item {...layout} label="微信学习提醒">
                                    微信学习提醒消息每  <Select style={{ width: 120 }} onChange={(e) => this.changeNumber(e, 'learn_alert')} value={learn_alert} placeholder="请选择天数">
                                    <Select.Option key="1" value={'0'}>请选择</Select.Option>
                                        <Select.Option key="5" value={5}>5</Select.Option>
                                        <Select.Option key="7" value={7}>7</Select.Option>
                                        <Select.Option key="14" value={14}>14</Select.Option>
                                        <Select.Option key="30" value={30}>30</Select.Option>
                                    </Select> 天发送一次学习提醒
                        </Form.Item>
                            </React.Fragment>
                        }
                        {/* */}
                        <Form.Item {...tailLayout}>
                            <Button type="primary" onClick={this.submitHandle}>提交</Button>
                        </Form.Item>
                    </Form>
                </Card>
            </PageContainer>
        );
    }
}

export default Index;

